package com.supermap.dataservice.order.dao;

import com.supermap.dubbo.api.order.entity.Service;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author:langhongshuai
 * @Description:服务数据访问层
 * @Date:18/6/19 上午10:14
 */
@Mapper
public interface ServiceDao {

    /**
     * 通过用户id获取用户的服务定制信息
     * @param userid
     * @return
     */
    @Select("select t1.*,if(ISNULL(t2.id),'0','1') as flag from t_service t1 "
            + "left join t_user_service t2 on t1.ID = t2.serviceid and t2.userid = #{userid};")
    List<Service> getAllServiceByUserId(@Param("userid") int userid);


    /**
     * 用户服务定制
     * @param userid
     * @param serviceid
     */
    @Insert("Insert into t_user_service(userid,serviceid) values(#{userid},#{serviceid})")
    void addUserService(@Param("userid") int userid, @Param("serviceid") int serviceid);

    /**
     * 用户定制服务删除
     * @param userid
     * @param serviceid
     */
    @Delete("delete from t_user_service where userid=#{userid} and serviceid=#{serviceid}")
    void delUserService(@Param("userid") int userid, @Param("serviceid") int serviceid);

    /**
     * 通过用户id和功能id检查服务是否被用户定制
     * @param userid
     * @param serviceid
     * @return
     */
    @Select("select t1.*,if(ISNULL(t2.id),'0','1') as flag from t_service t1 "
            + "left join t_user_service t2 on t1.ID = t2.serviceid "
            + "where t2.userid = #{userid} and t2.serviceid=#{serviceid}")
    List<Service> checkUserServiceExist(@Param("userid") int userid, @Param("serviceid") int serviceid);
}
